package cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.impl;

import cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.ICommodity;
import cn.zane.designPattern.createPatterns.factoryMethodPatterns.oldCode.coupon.CouponResult;
import cn.zane.designPattern.createPatterns.factoryMethodPatterns.oldCode.coupon.CouponService;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @Author: zane
 * @Date: 2024/12/25
 * @Description: 商品：优惠券服务
 */
@Slf4j
public class CouponCommodityService implements ICommodity {

    // 模拟注入
    private CouponService couponService = new CouponService();

    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        CouponResult couponResult = couponService.sendCoupon(uId, commodityId, bizId);
        log.info("请求参数[优惠券]->uId:{} commodityId:{} bizId:{} extMap:{}", uId, commodityId, bizId, JSON.toJSONString(extMap));
        log.info("测试结果[优惠券]:{}", JSON.toJSONString(couponResult));
        if (!"200".equals(couponResult.getCode())) {
            throw new RuntimeException(couponResult.getInfo());
        }
    }
}
